 <!--
* description: 网点编码选择
* author: wangjuan
* createdDate:
-->
<template>
  <el-dialog
    v-dialogDrag
    :title="topName"
    :visible="popupsVisible"
    :append-to-body="true"
    width="70%"
    center
    :close-on-click-modal="false"
    @close="closeEdit"
  >
    <dialogHeader
      slot="title"
      :title="topName"
      :style-type="$store.state.app.dialogType"
    />

    <one-table-template
      ref="multipleTable"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-table-defult-height="300"
      :dynamic-is-show-more-btn="false"
      :dynamic-is-show-select="false"
      :callback-obj="callbackObj"
    />
  </el-dialog>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import api from '@/api/pa/procuremenData'

export default {
  name: 'InstoreCode',

  components: {
    OneTableTemplate,
    dialogHeader: () => import('@/components/dialogHeader') // 弹窗标题,
  },

  mixins: [oneTableWithViewTemplateMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    code: { type: String, default: '' },
    comType: { type: String, default: '' },
    codeField: { type: String, default: '' },
    popupsKey: { type: String, default: '' },
    isMul: { type: Boolean, default: true },
    validrule: {
      type: Object,
      default: () => {}
    }
  },

  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      // 同时加载当前页面和编辑框页面的配置
      [to.path, ''],
      function() {
        next()
      })
  },

  data() {
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      topName: '入库单号',

      // 网格查询API配置对象
      apiConfig: api.queryPartByOrder,

      tableCols: this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
      this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols.length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols
        : [
          {
            prop: 'inStoreId ',
            label: '子单ID',
            hidden: true
          },
          {
            prop: 'dlrId',
            label: '备件ID',
            hidden: true
          },
          {
            prop: 'inStoreCode',
            label: '备件入库单编码'
          },
          {
            prop: 'billTypeCn',
            label: '单据类型'
          },
          {
            prop: 'inStoreDate',
            label: '入库日期'
          },
          {
            prop: 'inStoreAmount',
            label: '入库总金额'
          }
        ],

      formField: this.$utils.getFormField(this, {
        dlrId: '',
        dlrCode: '',
        dlrShortName: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode]),

      callbackObj: {
        onRowDbClick: (row, column, event) => {
          this.sendCode(row)
        }
      }

    }
  },

  methods: {
    sendCode(row) {
      // 获取嵌套组件的选中的值
      this.$emit('save', row)
      this.closeEdit()
    },

    // 关闭弹窗
    closeEdit(type) {
      this.$emit('close', type)
    }
  }
}
</script>
